//
//  Person.m
//  Runtime的使用
//
//  Created by caominglei on 2018/1/29.
//  Copyright © 2018年 caominglei. All rights reserved.
//

#import "Person.h"
#import <objc/message.h>

@implementation Person
void seat(id self,SEL _cmd)
{
    
    NSLog(@"调用seat %@ %@",self,NSStringFromSelector(_cmd));
}
+ (void)eat
{
    NSLog(@"类方法-吃东西");
}
- (void)eat
{
    NSLog(@"对象方法1-吃东西");

}
- (void)run:(int)meter
{
    NSLog(@"对象方法2-跑了%d米",meter);
    
}


/**
 动态添加方法,首先实现resolveClassMethod,作用：如没有实现，就会调用resolveClassMethod方法
 */
+ (BOOL)resolveInstanceMethod:(SEL)sel
{
    NSLog(@"%@",NSStringFromSelector(sel));
    if(sel == @selector(seat)){
        //运行时
        /*
         imp-方法实现，函数入口，函数名
         */
        class_addMethod(self, sel, (IMP)seat, "v@:");
    }
    return [super resolveClassMethod:sel];
}
@end
